package com.web3.management.controller;

import com.web3.management.dto.ApiResponse;
import com.web3.management.dto.response.ConfigDetailResponse;
import com.web3.management.service.ConfigMigrationService;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * 数据迁移控制器
 */
@RestController
@RequestMapping("/api/migration")
@RequiredArgsConstructor
@Validated
public class MigrationController {

    private final ConfigMigrationService migrationService;

    @PostMapping("/import-global-config")
    public ApiResponse<ConfigDetailResponse> importGlobalConfig(@Valid @RequestBody ImportConfigRequest request) {
        ConfigDetailResponse response = migrationService.importGlobalConfigFromFile(request.getFilePath());
        return ApiResponse.success("导入成功", response);
    }

    @PostMapping("/migrate-account-configs")
    public ApiResponse<ConfigMigrationService.MigrationResult> migrateAccountConfigs() {
        ConfigMigrationService.MigrationResult result = migrationService.migrateAccountConfigs();
        return ApiResponse.success(result);
    }

    @Data
    public static class ImportConfigRequest {
        @NotBlank(message = "文件路径不能为空")
        private String filePath;
    }
}
